import React from 'react';
import { Select, SelectProps, Spin } from 'antd';
import { useDictionaryOptions } from '@/hooks/useDictionary';

interface DictionarySelectProps extends Omit<SelectProps, 'options' | 'loading'> {
  code: string; // 字典类型编码
}

/**
 * 字典选择器组件
 * 自动从字典表加载选项数据
 */
const DictionarySelect: React.FC<DictionarySelectProps> = ({ code, ...props }) => {
  const { options, loading } = useDictionaryOptions(code);

  return (
    <Select
      {...props}
      options={options}
      loading={loading}
      notFoundContent={loading ? <Spin size="small" /> : '暂无数据'}
    />
  );
};

export default DictionarySelect;

